home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: seebs@solutions.solon.com (Peter Seebach)
- Newsgroups: comp.sources.wanted,comp.lang.c,comp.unix.programmer
- Subject: Re: Seek unix2dos.c OR help with tr
- Date: 10 Mar 1996 23:01:21 -0600
- Organization: Usenet Fact Police (Undercover)
- Message-ID: <4i0c31$r1g@solutions.solon.com>
- References: <4i0946$7io@nuke.csu.net>
- NNTP-Posting-Host: solutions.solon.com
-
- In article <4i0946$7io@nuke.csu.net>,
- Emmett Mclean <mclean@futon.SFSU.EDU> wrote:
- >Ah, writing the program is a bit trickier
- >than the little program below since the
- >program exits prematurely because getchar reads
- >EOF from its input - before getting to
- >the real EOF.
-
- >#include <stdio.h>
- >main(){
- >char c;
- >while(EOF!=(c=getchar())){
-
-
- ARGH!!!
-
- How many times must this be said?
-
- *getchar returns an int*. *NEVER* try to shove the return of getchar into a
- char *before you check for EOF*.
-
- Declare c as an int.
-
- > if(10==c)putchar(13);
- > putchar(c);
- > }
- > putchar(10);
- >}
-
- The last putchar(10) is wrong, but the guts of the code are probably
- correct.
-
- Assuming this is not a binary file; if it is, don't touch it.
-
- -s
- --
- Peter Seebach - seebs@solon.com - Copyright 1996 Peter Seebach.
- C/Unix wizard -- C/Unix questions? Send mail for help. No, really!
- FUCK the communications decency act. Goddamned government. [literally.]
- The *other* C FAQ - http://www.solon.com/~seebs/c/c-iaq.html
-